home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / bash-1.12 / dist / builtins / return.def < prev    next >
Encoding:
Text File  |  1991-07-09  |  1.7 KB  |  60 lines

  1. This file is return.def, from which is created return.c.
  2. It implements the builtin "return" in Bash.
  3.  
  4. Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU Bash, the Bourne Again SHell.
  7.  
  8. Bash is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 1, or (at your option) any later
  11. version.
  12.  
  13. Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  14. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License along
  19. with Bash; see the file COPYING.  If not, write to the Free Software
  20. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. $PRODUCES return.c
  23.  
  24. $BUILTIN return
  25.  
  26. $FUNCTION return_builtin
  27. $SHORT_DOC return [n]
  28. Causes a function to exit with the return value specified by N.  If N
  29. is omitted, the return status is that of the last command.
  30. $END
  31.  
  32. #include "../shell.h"
  33.  
  34. /* If we are executing a user-defined function then exit with the value
  35.    specified as an argument.  if no argument is given, then the last
  36.    exit status is used. */
  37. int
  38. return_builtin (list)
  39.      WORD_LIST *list;
  40. {
  41.   extern int last_command_exit_value;
  42.   extern int return_catch_flag, return_catch_value;
  43.   extern jmp_buf return_catch;
  44.  
  45.   return_catch_value = get_numeric_arg (list);
  46.  
  47.   if (!list)
  48.     return_catch_value = last_command_exit_value;
  49.  
  50.   if (return_catch_flag)
  51.     longjmp (return_catch, 1);
  52.   else
  53.     {
  54.       builtin_error ("Can only `return' from a function");
  55.       return (EXECUTION_FAILURE);
  56.     }
  57. }
  58.  
  59.  
  60.